<template>
  <div class="w-[100%] h-[100%]">

    <div class="mt-[30px]">
      <ContentWrap>
        <SearchBox :queryForm="searchList" :showExpland="true" @query="handleSearchQuery"/>
      </ContentWrap>
    </div>

    <div class="mt-[30px]">
      <el-button
        type="primary"
        plain
        @click="handleBtnClick({type:'add'})"
        round
        class="flex-center"
      >
        <Icon icon="ep:plus"/>
        新增模板
      </el-button>
    </div>

    <div class="mt-[30px]">
      <QueryTable
        :list="dataList"
        :total="total"
        :btns="tableBtnList"
        @execute="handleBtnClick"
        v-model="queryParams"
        :thead="th"
        :show-action="true"
      />

    </div>
    <InfoAction v-model="isShowDialog" :info="selectedRow"/>
  </div>
</template>
<script setup lang="ts">
import Icon from "@/components/Icon/src/Icon.vue"
import QueryTable from "@/components/TableData/index.vue"
import ImagePreview from "@/components/ImagePreview/index.vue"
import InfoAction from "./components/InfoAction.vue";
import type {TradeOrderQueryVO} from "@/api/mall/trade/order";
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
import type {PurchaseAdvice} from "@/api/purchase/advice/type";
import {throttle,confirmPromote} from "@/utils";

const searchList: TradeOrderQueryVO[] = [
  {
    label: '订单编号',
    code: 'orderNo',
    type: 'input'
  },

  {
    label: '地区',
    code: 'area',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '下单日期',
    code: 'orderTime',
    type: 'dateRange'
  },
  {
    label: '商品信息',
    code: 'shopInfo',
    type: 'input',
    placeHolder: '商品名称/商品ID/sku'
  },
  {
    label: '下单信息',
    code: 'orderInfo',
    type: 'input'
  },
  {
    label: '下单链接',
    code: 'orderLink',
    type: 'input'
  },
  {
    label: '物流单号',
    code: 'no ',
    type: 'input'
  },
  {
    label: '归属部门',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '归属人员',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '订单来源',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: 'IP',
    code: 'no',
    type: 'input'
  },
  {
    label: '留言/备注',
    code: 'message',
    type: 'input'
  },
  {
    label: '订单状态',
    code: 'status',
    type: 'select',
    options: getIntDictOptions(DICT_TYPE.TRADE_ORDER_STATUS)
  },
  {
    label: '是否有物流单',
    code: 'status',
    type: 'select',
    options: getIntDictOptions(DICT_TYPE.TRADE_ORDER_STATUS)
  },
  {
    label: '是否推物流',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '是否有效订单',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '物流状态',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '内部编码',
    code: 'no',
    type: 'input'
  },
  {
    label: '支付方式 ',
    code: 'dept',
    type: 'select',
    options: [
      {
        label: '中国',
        value: 'CN'
      },
      {
        label: '美国',
        value: 'US'
      }
    ]
  },
  {
    label: '支付单号',
    code: 'no',
    type: 'input'
  }
]
const initQueryParams = {
  pageNo: 1, pageSize: 10
}

const tableBtnList = ref([
  {
    color: '#3721FF',
    code: 'edit',
    name: '编辑'
  },
  {
    color: '#FF4E00',
    code: 'delItem',
    name: '删除'
  }
]);


const th = ref([
  {
    name: '模板名称',
    code: 'name',
    type: 'numberRanger',
    search: true
  },
  {
    name: '地区',
    code: 'area',
    type: 'date',
    search: true
  },
  {
    name: '模板类型',
    code: 'type',
    search: false
  },
  {
    name: '是否启用',
    code: 'isOpen',
    type: 'numberRanger',
    search: true
  },
  {
    name: '创建者',
    code: 'creator',
    search: false
  },
  {
    name: '创建时间',
    code: 'creatTime',
    search: false
  },

]);
const dataList = ref<PurchaseAdvice[]>([

  {
    name: "发货模板",
    area: "克孜勒苏柯尔克孜自治州",
    type: "取件通知",
    isOpen: true,
    creator: "高级销售员",
    creatTime: "2025-12-12 12:12:12"
  },
  {
    name: "发货模板",
    area: "克孜勒苏柯尔克孜自治州",
    type: "取件通知",
    isOpen: true,
    creator: "高级销售员",
    creatTime: "2025-12-12 12:12:12"
  }


]);
const ids = ref<Array<string | number>>([]);
const total = ref(0);

const initRow = {
  cover: null,
  sku: null,
  spec: null,
  name: null,
  productId: null,
  advice: null,
  occupy: null,
  stock: null,
  inTransit: null,
  noAuditInTransit: null,
}

const selectedRow = ref<PurchaseAdvice>({...initRow})

const isShowDialog = ref(false)


const queryParams = ref({
  ...initQueryParams
})

const handleSearchQuery = (val) => {
  /***
   * 搜索框查询条件，目前考虑在查询时 queryParams = {...val,pageNo:1,pageSize:10}
   * */
  console.log(val, 'handleSearchQuery')
}

const handleBtnClick = e => {
  let type = e.type;
  try {
    fn[type](e)
  } catch (e) {
    console.log(`${type}不存在`)
  }
}

const fn = {
  add({data}) {
    selectedRow.value = {};
    isShowDialog.value = true
  },
  edit({data: {row}}) {
    selectedRow.value = row
    isShowDialog.value = true
  },
  delItem:throttle(async()=>{
    await confirmPromote({
      content:"确认删除数据吗？"
    })

  },1000)
}


</script>
<style lang="scss" scoped>

</style>
